package com.b.btest;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ListArtistAdapter extends ArrayAdapter<Artist> {

	LayoutInflater mInflater;

	public ListArtistAdapter(Context context, List<Artist> item) {
		super(context, 0, item);

		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		Artist item = getItem(position);
		ViewHolder holder;

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_artist, null);
			holder = new ViewHolder();
			holder.artistTextView = (TextView) convertView.findViewById(R.id.artistArtist);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.artistTextView.setText(item.artist);

		if (position % 2 == 0) {
			convertView.setBackgroundColor(Color.argb(50, 255, 50, 0));
		}
		else {
			convertView.setBackgroundColor(Color.argb(50, 250, 250, 250));
		}

		return convertView;
	}

	static class ViewHolder {
		TextView artistTextView;
	}
}
